#pragma once
#include <iostream>


//目标抽象类DataOperation（数据操作类）
class DataOperation{
public:
	void setPassword(std::string password){
		this->password = password;
	}
	std::string getpassword(){
		return this->password;
	}
	virtual std::string doEncrypt(int key,std::string ps) = 0;
private:
	std::string password;
}; 


//适配器类Caesar（数据加密类）
class Caesar{
public:
	std::string doEncrypt(int key,std::string ps){
		std::string es = "";
		for(int i = 0 ; i < ps.length() ; i++){
			char c = ps.at(i);
			if(c>='a' && c<='z'){
				c+= key%26;
				if(c>'z'){
					c-=26;
				}
				if(c<'a'){
					c+=26;
				}
			}
			if(c>='A' && c<='Z'){
				c+=key%26;
				if(c>'Z'){
					c-=26;
				}
				if(c<'A'){
					c+=26;
				}
			}
			es+=c;
		}
		return es;
	}
}; 


//适配器类CipherAdapter（加密适配器类）
class CipherAdapter : public DataOperation{
 
public:
	CipherAdapter(){
		cipher = new Caesar();
	}
	
	std::string doEncrypt(int key,std::string ps){
		return cipher->doEncrypt(key,ps);
	}
private:
	Caesar *cipher;
}; 